<template>
	<view class="content b-t">
		<!-- 空白页 -->
		<view v-if="empty===true" class="empty">
					<image src="/static/img/1/92.png" mode="aspectFit"></image>
				
					<view class="empty-tips">
						收货地址在哪里
						
					</view>
		</view>
		<image v-if="empty===false" src="/static/img/1/27.png" mode="aspectFill" class="i-header"></image>
		
		<view v-if="empty===false" class="list b-b" v-for="(item, index) in addressList" :key="index" @click="checkAddress(item)">
			
			<view class="wrapper">
				<view class="u-box">
					<text class="name clamp">{{item.cReceiver}}</text>
					<text class="mobile">{{item.cMobile}}</text>
				</view>
				<view class="address-box">
					<text v-if="item.bDefault" class="tag">默认</text>
					<text v-if="!item.bDefault" class="tags"></text>
					<text class="address">{{item.cProvince}} {{item.cCity}} {{item.cArea}} {{item.cAddress}}</text>
				</view>
				
			</view>
			<image src="/static/img/1/93.png" mode="aspectFit" class="edit" @click.stop="addAddress('edit',item)"></image>
		</view>
		
		
		<button class="add-btn" @click="addAddress('add')">+新建地址</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				source: 0,
				empty: false, //空白页现实  true|false
				addressList: [
					
				]
			}
		},
		onLoad(option){
			console.log(option.source);
			// this.source = option.source;
			
			this.getList()
			
		},
		methods: {
			//获取地址列表
			getList(){
				let token = this.$SysCache.get('token')||null
				this.$Request.get(this.$api.httpApi.address.list+"&token="+this.$SysCache.get('token')).then(res => {
				if (res.code == 200) {
						if(res.data){
							this.addressList = res.data
							this.empty = false
						}else{
							this.empty = true
						}
						
					}
				})
			},
			//选择地址
			checkAddress(item){
				// if(this.source == 1){
					//this.$api.prePage()获取上一页实例，在App.vue定义
					this.$api.prePage().addressData = item;
					uni.navigateBack()
				// }
			},
			addAddress(type, item){
				uni.navigateTo({
					url: `/pages/address/add?type=${type}&data=${JSON.stringify(item)}`
				})
			},
			//添加或修改成功之后回调
			refreshList(data, type){
				//添加或修改后事件，这里直接在最前面添加了一条数据，实际应用中直接刷新地址列表即可
				// this.addressList.unshift(data);
				this.getList()
				
				// console.log(data, type);
			}
		}
	}
</script>

<style lang='scss'>
	page{
		padding-bottom: 120upx;
		background: #f5f5f5;
	}
	.content{
		position: relative;
		.empty{
			position:fixed;
			left: 0;
			top:0;
			width: 100%;
			height: 100vh;
			padding-bottom:173upx;
			display:flex;
			justify-content: center;
			flex-direction: column;
			align-items:center;
			
			image{
				width: 249upx;
				height: 248upx;
				margin-bottom:10upx;
			}
			.empty-tips{
				display:flex;
				font-size:23upx;
				font-family:Microsoft YaHei;
				font-weight:400;
				color:rgba(102,102,102,1);
				
			}
		}
		.i-header {
			width: 100%;
			height: 10upx;
			display: block;
		}
	}
	.list{
		display: flex;
		align-items: center;
		padding: 20upx 30upx;;
		background: #fff;
		position: relative;
		
	}
	.wrapper{
		display: flex;
		flex-direction: column;
		flex: 1;
	}
	.edit{
		width:46upx;
		height:45upx;
	}
	.address-box{
		display: flex;
		align-items: center;
		margin-top: 15upx;
		margin-bottom: 17upx;
		.tag{
			width:35px;
			height:33upx;
			background:rgba(255,255,255,1);
			border:1upx solid rgba(240, 64, 111, 1);
			border-radius:5upx;
			font-size:21upx;
			font-family:Microsoft YaHei;
			font-weight:400;
			color:rgba(240,64,111,1);
			display: inline-flex;
			justify-content: center;
			align-items: center;
			margin-right: 45px;
		}
		.tags{
			display: inline-flex;
			width:35px;
			height:33upx;
			margin-right: 45px;
		}
		.address{
			font-size:27upx;
			font-family:Microsoft YaHei;
			font-weight:400;
			color:rgba(102,102,102,1);
			flex: 1;
		}
	}
	.u-box{
		font-size:27upx;
		font-family:Microsoft YaHei;
		font-weight:400;
		color:rgba(102,102,102,1);
		display: flex;
		margin-top: 21upx;
		.name{
			margin-right: 10px;
			display: inline-block;
			width: 70px;
		}
	}
	.icon-bianji{
		display: flex;
		align-items: center;
		height: 80upx;
		font-size: 40upx;
		color: $font-color-light;
		padding-left: 30upx;
	}
	
	.add-btn{
		position: fixed;
		left: 30upx;
		right: 30upx;
		bottom: 100upx;
		z-index: 95;
		display: flex;
		align-items: center;
		justify-content: center;
		width:698upx;
		height:73upx;
		background:rgba(240,64,111,1);
		border-radius:36upx;
		font-size:23upx;
		font-family:Microsoft YaHei;
		font-weight:400;
		color:rgba(255,255,255,1);
			
	}
</style>
